import java.util.Arrays;

public class Test {
    public static void maoPaoSort(int[] array) {        //数组的传参是传的引用
        for (int i = 0; i < array.length - 1; i++) { //五个数只需要比较三次
            boolean flag = false; //每次只能优化一个数字，但是每趟都在所有数比较，只需要比较一次全部让他们有序那么整个数组就是有序的
            for (int j = 0; j < array.length - i - 1; j++) { //每一趟比上次少一次比较
                if (array[j] > array[j + 1]) { //交换
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flag = true; //执行交换了就置flag
                }
            }
            if (flag == false) {
                //如果有序
                return ;
            }
        }
    }
    public static void main1(String[] args) {
        int[] arr = new int[]{1, 3, 5, 63, 8, 3};
        String ret = Arrays.toString(arr);
        System.out.println(ret);
        System.out.println("===========");
        maoPaoSort(arr);
        String ret1 = Arrays.toString(arr);
        System.out.println(ret1);
    }
    public static void revers(int[] array){
        int left = 0;
        int right = array.length-1;
        while(right>left){
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            right--;
            left++;
        }
    }
    public static void main3(String[] args) {
        //逆置数组
        int[] arr = new int[]{1,2,3,4,5};
        revers(arr);
        String ret = Arrays.toString(arr);
        System.out.println(ret);
    }

    public static void main5(String[] args) {
        //二维数组
        int[][] array = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("===========");
        for (int[] tmp: array) {
            for (int x: tmp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println("==========");
        System.out.println(Arrays.deepToString(array));//以一维数组的形式打印二位
        System.out.println("==========");
        int[][] array2= new int[2][];
        array2[0] = new int[3];
        array2[1] = new int[5];
        System.out.println(Arrays.deepToString(array2));
    }

    public static void main(String[] args) {

    }
}
